#include <iostream>   //对应 C里的 stdio.h
#include <string> //C ++ string 类头文件
#include <cstring> //string.h  C 字符串相关函数头文件
using namespace std;

class MyList{
	class Node{//内部类
		int		data;
		Node*	pNext;
	public:
		Node(int data) :data(data){ pNext = NULL; }
		Node* getNext()const{ return pNext; }
		void setNext(Node* p){ pNext = p; }
		int getData(){ return data; }
	};
	Node* pHead;
public:
	MyList(){ pHead = NULL; }
	void travel();
	void push_back(int data);
    void push_front(int data);
};

void MyList::push_front(int data)
{
    if (pHead){
		Node* newNode = new Node(data);
        newNode->setNext(pHead);
        pHead = newNode; 
	}
	else{
		pHead = new Node(data);
	}
}

void MyList::push_back(int data){
	if (pHead){
		Node* pTail = pHead;
		while (pTail->getNext()){
			pTail = pTail->getNext();
		}
		pTail->setNext(new Node(data));
	}
	else{
		pHead = new Node(data);
	}
}
void MyList::travel() {
	cout << "list:";
	Node* pTemp = pHead;
	while (pTemp){
		cout << pTemp->getData() << " ";
		pTemp = pTemp->getNext();
	}
	cout << endl;
}

int main(){
	MyList l;

	for (int i = 0; i < 10; i++)
		l.push_front(i), l.travel();


	
	while (1);
	return 0;
}